<!DOCTYPE html>
<html>
<head>

</head>

<body ontouchstart>
 <script src="${base}/templates/${config.theme}/mobile/js/jquery.min.js"></script>
 <script src="${base}/templates/${config.theme}/mobile/js/jweixin-1.2.0.js"></script>
 <script type="text/javascript" src="${base}/templates/${config.theme}/mobile/static/js/ajax.js"></script>
 <script>
    $(function() {
         	var unionid=localStorage.getItem('unionid');
        	var token=localStorage.getItem('token');
        	if(token){
        	  window.top.location="index.html";
        	  return;
        	}
            var code=GetQueryString("code");
	        	var crtName=GetQueryString("crtName");

	        	if(crtName){
	        		 localStorage.setItem('crtName',crtName);
	        	}
        	if(unionid){
        		login(unionid) ;
        	}else{

	        	if(code){
	        		getUnionid(code);
	        	}else{
	        		location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8d63715e2d5caec7&redirect_uri="
	        		   +"https://hanjiayx.com/weix/&response_type=code&scope=snsapi_base&state=yunnying#wechat_redirect";
	        	}

        	}

        });






function getUnionid(code){
    $.axse("/weix/denlu",{ code: code },
        function(data){
            if(data.rel){
                localStorage.setItem('unionid',data.result.openid);
                login(data.result.openid) ;
            }
        },
        function(data){
       });

}

function GetQueryString(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}

function login(unionid) {
	var formData={"unionid":unionid};
	localStorage.setItem('unionid',unionid);
    $.axse("/weix/codeLogin",formData,
        function(data){
            if(data.rel){
                window.top.location="../";
            }else{
                localStorage.setItem('name',data.result.nickname);
                localStorage.setItem('headimgurl',data.result.headimgurl);
                //alert(ret.result.nickname);
                window.top.location="register";
            }
        },
        function(data){
        });

}
    </script>
</body>
</html>
